package com.teacold.customdemo.recyclerdemo;


import java.util.ArrayList;

import androidx.recyclerview.widget.DiffUtil;

public class RecyclerDiffCallback extends DiffUtil.Callback {
    private ArrayList<RecyclerBean> oldData;
    private ArrayList<RecyclerBean> newData;


    public RecyclerDiffCallback(ArrayList<RecyclerBean> oldData, ArrayList<RecyclerBean> newData) {
        this.oldData = oldData;
        this.newData = newData;
    }

    @Override
    public int getOldListSize() {
        return oldData.size();
    }

    @Override
    public int getNewListSize() {
        return newData.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return oldData.get(oldItemPosition).getmId().equals(newData.get(newItemPosition).getmId());
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        String oldID=oldData.get(oldItemPosition).getmId();
        String newId=newData.get(newItemPosition).getmId();
        return oldID.equals(newId);
    }
}
